#include "myFunctions.h"
#include "bpNet.h"

int main(int argc,char *argv[]){
	bpNet Network;
  int neurons[] = {2,7,1};

	float **vRand;
  float **targets;
  
	int numPatterns = 1000;
	int maxEpocas = 10000;
  double deltaError = 0.01;
  
  vRand = (float**)calloc(numPatterns,sizeof(float *));
  targets = (float **)calloc(numPatterns,sizeof(float*));
  for (int i=0; i<numPatterns ; i++){
		vRand[i] = (float *)calloc(2,sizeof(float));  //10000x2                       
		targets[i] = (float *)calloc(1,sizeof(float));  //10000x1
	}     

	for (int i=0;i<numPatterns;i++){
		vRand[i][0] = normRandom() * 4 - 2;
		vRand[i][1] = normRandom() * 4 - 2;
		if (fabs(vRand[i][0]) >= 1.0 )
			targets[i][0] = 1.0;
		else
			targets[i][0] = (fabs(vRand[i][1]) >=1 ) ? 1.0 : -1.0; 		 
	}
	Network.init(neurons,3);
	Network.setMomentum(0);
  Network.RandomWeights();  

	if (Network.BpTrain(vRand,targets,numPatterns,maxEpocas,deltaError)) { 
		cout<<"Entreno"<<endl;
		Network.Save("cuadrado.txt");
	}
	else cout<<"Falta entrenar"<< endl; 
	return 1;
}
